extends Node2D

const time = ["7:30","7:40","8:00","12:00","12:20-12:50","13:00-16:00","17:00-20:00","21:00-7:30"]
const events = ["起床","吃早饭","上班","吃午饭","午休","上班","运动","睡觉"]
var index = 0
var current_event = ""
enum shenjin {zhu,fu}
enum naobo {beita,aerfa,xita,dererta}
var current_naobo = naobo.beita
var curret_shenjin = shenjin.zhu
var can_wake = false
var changed_shenjin = false
var day = 0 #生存多少天

func _ready():
	$Events/events.text = "当前事件:" + events[index]
	$Events/time.text = "时间:" + time[index]
	current_event = events[index]
	pass

func _on_Zhujiaogan_pressed():
	$ZhiBiao/shenjin.text = "目前神经：主交感神经"
	changed_shenjin = true
	curret_shenjin = shenjin.zhu
	if current_event == "午休" or current_event == "睡觉":
		add_error()
	pass

func _on_Fujiaogan_pressed():
	$ZhiBiao/shenjin.text = "目前神经：副交感神经"
	#changed_shenjin = true
	curret_shenjin = shenjin.fu
	if current_event == "起床" or current_event == "吃早饭" or current_event == "上班" or current_event == "吃午饭" or current_event == "运动":
		add_error()
	pass

func _on_Beita_pressed():
	$ZhiBiao/naobo.text = "脑波：β波"
	current_naobo = naobo.beita
	if current_event == "午休" or current_event == "睡觉":
		add_error()
	#if changed_shenjin:
		#$Events/Next.disabled = false
	pass

func _on_Aerfa_pressed():
	$ZhiBiao/naobo.text = "脑波：α波"
	current_naobo = naobo.aerfa
	if current_event == "起床" or current_event == "吃早饭" or current_event == "上班" or current_event == "吃午饭" or current_event == "运动":
		add_error()
	#if changed_shenjin:
		#$Events/Next.disabled = false
	pass

func _on_Xita_pressed():
	$ZhiBiao/naobo.text = "脑波：θ波"
	current_naobo = naobo.xita
	if current_event == "起床" or current_event == "吃早饭" or current_event == "上班" or current_event == "吃午饭" or current_event == "运动":
		add_error()
	#if changed_shenjin:
	#	$Events/Next.disabled = false
	pass

func _on_Deerta_pressed():
	$ZhiBiao/naobo.text = "脑波：δ波"
	current_naobo = naobo.dererta
	if current_event == "起床" or current_event == "吃早饭" or current_event == "上班" or current_event == "吃午饭" or current_event == "运动":
		add_error()
	#if changed_shenjin:
	#	$Events/Next.disabled = false
	pass

func add_error():
	$ProgressBar.value += 10
	pass

# 有bug要修，应该是在每次按下事件处理按钮时候，判断事件来进行处理
# 所有的上班时间，如果副交感 或者脑波不等于beita就增加错误值
func _on_Next_pressed():
	if $ProgressBar.value >= 100:
		$Panel/Label.text += "存活了" + str(day) + "天"
		$Panel.show()
		pass
	show_next()
	pass
	
func show_next():
	if index < len(events) -1:
		index += 1
	else:
		index = 0
		day +=1
		$Day.text = "第" + str(day) + "天"
	current_event = events[index]
	$Events/events.text = "当前事件:" + events[index]
	$Events/time.text = "时间:" + time[index]
	pass
	
func _on_Back_pressed():
	get_tree().change_scene("res://scene/Main.tscn")
	pass
